package com.electric.qrapp.utils.databinding

import android.widget.TextView
import androidx.appcompat.widget.AppCompatImageView
import androidx.databinding.BindingAdapter
import com.electric.qrapp.utils.function.ImageLoader
import com.electric.qrapp.utils.function.conversionColor


/**
 *@author:Fanatic
 *@date:2021/8/8 12:20
 *@des:
 */
object BindingUtils {



    @JvmStatic
    @BindingAdapter("setCircleImg", requireAll = false)
    fun setCircleImg(iv: AppCompatImageView, url: Any?) {
        url?.run {
            ImageLoader.circleLoad(iv, url)
        }
    }


    @JvmStatic
    @BindingAdapter("bindMContent", "bindMKeyWord", "bindColor", requireAll = false)
    fun bindMContent(tv: TextView, content: String?, keyWord: String?, colorId: Int) {
        content?.run {
            var startIndex = 0
            var endIndex = this.length

            if (!keyWord.isNullOrEmpty() && this.contains(keyWord)) {
                startIndex = this.lastIndexOf(keyWord)
            }
            tv.text = conversionColor(this, colorId, startIndex, endIndex)
        }
    }
 }
